import java.util.Scanner; // 需要导入 util 包
public class Test {
    private static int count = 0;
    public static void main(String[] args){

        hanio(3,'x','y','z');
        System.out.println(" 总共移动了 " + count + " 次" );

       /* System.out.println(maxs(2, 4, 6));
        System.out.println(maxs(2, 9, 6));
        System.out.println(maxs(10, 9, 6));


*/


        /*int[]array = new int[]{10, 20, 30, 40, 50};
        for (int x:array) {
            System.out.println(x);
        }
*/
        /*for(int i = 0; i < array.length; i++){

        }*/

       /* int[]arr = new int[]{10, 20, 30, 40, 50};
        System.out.println(arr[0]);
        System.out.println(arr[1]);
        System.out.println(arr[2]);
        System.out.println(arr[3]);
        System.out.println(arr[4]);
        System.out.println(arr[5]);
*/
        /*int[] arr1 = {1,2,3,1,1,1,1,1,1,1,1};
        int[] arr2 = new int[10];
        int[] arr3 = new int[]{1,2,3,5,4,5,9};*/


       /* Scanner sc = new Scanner(System.in);
        System.out.println("请输入你的姓名：");
        String name = sc.nextLine();
        System.out.println("请输入你的年龄：");
        int age = sc.nextInt();
        System.out.println("请输入你的工资：");
        float salary = sc.nextFloat();
        System.out.println("你的信息如下：");
        System.out.println("姓名: "+name+"\n"+"年龄："+age+"\n"+"工资："+salary);
        sc.close(); // 注意, 要记得调用关闭方法*/


        /*System.out.println("hello world换行");
        System.out.print("不换行 ");
        int x = 10;
        System.out.printf("x = %d\n", x);*/

        // 求两个整数的最大值
        /*int a = 10;
        int b = 20;
        int max = a > b ? a : b;

        int a = 1;
        System.out.println(!(a == 1)); // a == 1 为true，取个非就是false
        System.out.println(!(a != 1)); // a != 1 为false，取个非就是true*/

        /*int a = 1;
        int b = 2;
        System.out.println(a == 1 && b == 2); // 左为真 且 右为真 则结果为真
        System.out.println(a == 1 && b > 100); // 左为真 但 右为假 则结果为假
        System.out.println(a > 100 && b == 2); // 左为假 但 右为真 则结果为假
        System.out.println(a > 100 && b > 100); // 左为假 且 右为假 则结果为假

        System.out.println(a == 1 || b == 2); // 左为真 且 右为真 则结果为真
        System.out.println(a == 1 || b > 100); // 左为真 但 右为假 则结果也为真
        System.out.println(a > 100 || b == 2); // 左为假 但 右为真 则结果也为真
        System.out.println(a > 100 || b > 100); // 左为假 且 右为假 则结果为假*/

        /*int a = 10;
        int b = 20;
    // 注意：在Java中 = 表示赋值，要与数学中的含义区分
    // 在Java中 == 表示相等
        System.out.println(a == b); // false
        System.out.println(a != b); // true
        System.out.println(a < b); // true
        System.out.println(a > b); // false
        System.out.println(a <= b); // true
        System.out.println(a >= b); // false*/

        /*int a = 1;
        a++; // 后置++ 表示给a的值加1，此时a的值为2
        System.out.println(a++); // 注意：后置++是先使用变量原来值，表示式结束时给变量+1，因此输出2
        System.out.println(a); // 输出3
        ++a; // 前置++ 表示给a的值加1
        System.out.println(++a); // 注意：前置++是先给变量+1，然后使用变量中的值，因此输出5
        System.out.println(a); // 输出5
       // --操作符给操作-1，与++含义类似
*/
        /*int a = 1;
        a += 2; // 相当于 a = a + 2
        System.out.println(a); // 输出3
        a -= 1; // 相当于 a = a - 1
        System.out.println(a); // 输出2
        a *= 3; // 相当于 a = a * 3
        System.out.println(a); // 输出6
        a /= 3; // 相当于 a = a / 3
        System.out.println(a); // 输出2
        a %= 3; // 相当于 a = a % 2
        System.out.println(a); // 输出2*/

        /*int a = 20;
        int b = 10;
        System.out.println(a + b); // 30
        System.out.println(a - b); // 10
        System.out.println(a * b); // 200
        System.out.println(a / b); //
        System.out.println(a % b); // 0 --->模运算相当于数学中除法的余数
        */





       /* for(int i = 0;i < arr3.length;i++){
            System.out.println(arr3[i]);
        }*/
        /*for (int x:arr1) {
            System.out.println(x);
        }
        */
        /*System.out.println(fib1(20));
        System.out.println(fib(20));
*/
        // System.out.println(sum(1729));

        // System.out.println(add(10));

        /*int[] arr = {10,20};
        System.out.println("交换前；" + arr[0] + " " +  arr[1]);
        swap(arr);
        System.out.println("交换后；" + arr[0] + " " +  arr[1]);*/

        /*System.out.println("结果为" + facSum(5));*/
/*
        System.out.println("调用方法前");
        System.out.println("调用方法后:" + Add(10,20));
*/

        /*boolean falg = isLeapYear(2004);
        if(falg){
            System.out.println("是闰年");
        }else{
            System.out.println("不是闰年");

        }*/


    }

    public static void hanio(int n, char x, char y, char z) {
        count++;
        if(n==1) {
            move(x,n,z);
        }else {
            hanio(n-1,x,z,y);
            move(x,n,z);
            hanio(n-1,y,x,z);
        }

    }

    private static void move(char x, int n, char y) {
        // TODO Auto-generated method stub
        System.out.println(" Move " + n + " from " + x + " to " + y);
    }


    public static int max(int a,int b){
        return a > b ? a : b;
    }
    public static double max(double a,double b){
        return a - b > 0 ? a : b;

    }

    public static int maxs(int a,int b,int c){
        return max(a,b) > max(b,c) ? max(a,b) : max(b,c);
    }

    public static int fib1(int n){
        if(n == 1){
            return 0;
        }
        if(n == 2){
            return 1;
        }
        int last2 = 1;
        int last1 = 0;
        for(int i = 3;i <= n;i++){
            int tmp = last1 + last2;
            last1 = last2;
            last2 = tmp;
        }
        return last2;
    }


    public static int fib(int n){
        if(n == 1){
            return 0;
        }
        if(n == 2){
            return 1;
        }
        return fib(n - 1) + fib(n - 2);
    }


    public static int sum(int num){
        if(num < 10){
            return num;
        }else{
            return num % 10 + sum(num / 10);
        }
    }

    public static int add(int num){
        if(num == 1){
            return 1;
        }else{
            return num + add(num-1);
        }
    }

    public static void print(int n){
        if(n > 10){
          print(n / 10);
        }
        System.out.println(n % 10 + " ");
    }

    public static int factor(int n){
        if(n == 1){
            return 1;
        }else{
            return n * factor(n-1);
        }
    }


    public static double Add(int a,int b){
        return a + b;
    }


    public static double Add(double a,double b,double c){
        return a + b + c;
    }

    public static int Add(char a,char b,char c){
        System.out.println("调用方法中x = " + a + "y = "+ b);
        return a + b + c;
    }

    public static void swap(int[] arr){
        int tmp = arr[0];
        arr[0] = arr[1];
        arr[1] = tmp;
    }

    public static int fac(int n){
        int result = 1;
        System.out.println("计算" + n + "的阶乘中");
        for(int i = 1;i <= n;i++){
            result *= i;
        }
        return result;
    }

    public static int facSum(int n){
        int sum = 0;
        for(int i = 1;i <= n;i++){
            sum += fac(i);
            System.out.println("相加目前为" + sum);
            System.out.println();
        }
        return sum;
    }



    public static boolean isLeapYear(int year){
        if((0 == year % 4 && 0 != year % 100) || 0 == year % 400){
            return true;
        }else{
            return false;
        }
    }

}
